//
//  OrderSubmitBottom.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/5/5.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
import UIKit
class OrderSubmitBottom:UIView{
    var totalAmountLabel = UILabel()
    var totalScoreLabel = UILabel()
    var submitBtn = UIButton()
    var ostatus:Int!//订单状态
    override func layoutSubviews() {
        super.layoutSubviews()
        let label1 = UILabel()
        label1.text = "总金额：￥"
        label1.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(label1)
        label1.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(2)
            make.height.equalTo(15)
            make.width.equalTo(65)
            make.left.equalTo(self).offset(10)
        }
        totalAmountLabel.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(totalAmountLabel)
        totalAmountLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(2)
            make.height.equalTo(15)
            make.width.equalTo(kScreenW  - 170)
            make.left.equalTo(70)
        }
        let label2 = UILabel()
        label2.text = "总扣分："
        label2.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(label2)
        label2.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(2)
            make.width.equalTo(90)
            make.right.equalTo(-10)
            make.height.equalTo(15)
        }
        totalScoreLabel.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(totalScoreLabel)
        totalScoreLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(2)
            make.height.equalTo(15)
            make.width.equalTo(40)
            make.right.equalTo(label2.snp.right)
        }
        //细分割线
        let bseparator1 = UILabel()
        bseparator1.backgroundColor = tableBgColor
        self.addSubview(bseparator1)
        bseparator1.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(label1.snp.bottom).offset(2)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        submitBtn = UIButton(type: .custom)
        submitBtn.setTitleColor(UIColor.white, for: .normal)
        submitBtn.backgroundColor = appMainColor
        submitBtn.tag = ostatus
        
        let vsc = ViolationSubmitController()
        if 0 == ostatus  {
            submitBtn.setTitle("去支付", for: .normal)
            submitBtn.addTarget(vsc, action: #selector(vsc.alertFun(sender:)), for: UIControlEvents.touchUpInside)
        }else {
            if "1" == isEmployee {//普通用户登录
                if 1 == ostatus {
                    submitBtn.setTitle("等待处理", for: .normal)
                    submitBtn.isEnabled = false
                    submitBtn.backgroundColor = UIColor.lightGray
                }
                if 2 == ostatus {
                    submitBtn.setTitle("处理中", for: .normal)
                    submitBtn.backgroundColor = UIColor.lightGray
                    submitBtn.isEnabled = false
                }
                if 3 == ostatus {
                    submitBtn.setTitle("已处理", for: .normal)
                    submitBtn.isEnabled = false
                    submitBtn.backgroundColor = UIColor.lightGray
                }
            }
            if("2" == isEmployee){
                if 1 == ostatus {
                    submitBtn.setTitle("抢单", for: .normal)
                    submitBtn.addTarget(vsc, action: #selector(vsc.alertFun(sender:)), for: UIControlEvents.touchUpInside)
                }
                if 2 == ostatus {
                    submitBtn.setTitle("完成", for: .normal)
                    submitBtn.addTarget(vsc, action: #selector(vsc.alertFun(sender:)), for: UIControlEvents.touchUpInside)
                }
                if 3 == ostatus {
                    submitBtn.setTitle("已完成", for: .normal)
                    submitBtn.backgroundColor = UIColor.lightGray
                    submitBtn.isEnabled = false
                }
            }
        }
        submitBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        submitBtn.showsTouchWhenHighlighted = true
        submitBtn.layer.cornerRadius = 5
        self.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) in
            make.height.equalTo(35)
            make.width.equalTo(self.sd_width - 20)
            make.centerX.equalTo(self.snp.centerX)
            make.bottom.equalTo(self.snp.bottom).offset(-10)
        }
    }
}
